﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SQLServerHealthCheck.Model
{
    public partial class Service
    {
        public String InstanceName
        {
            get
            {
                return String.IsNullOrEmpty(this.Name) ? this.Server.Name : this.Server.Name + "\\" + this.Name;
            }
        }

        public string GetConnectionString(string database)
        {

            string connectionString = "";
            
            string portNumber = Port.HasValue && Port != 1433? "," + Port : "";
          
            if (Authentication == "Windows Authentication")
            {
                connectionString = string.Format("Server={0}{1};Database={2};Integrated Security=True;", InstanceName, portNumber, database);

            }
            else
            {
                connectionString = string.Format("Server={0}{1};Database={2};Integrated Security=False;User Id={3};Password={4}", InstanceName, portNumber, database, Login, Password);
            }
            return connectionString;

        }


    }
}
